package com.klb.action.catalog;

import com.klb.service.catalog.impl.BlockServiceCatalogImpl;
import com.klb.tools.Sessions;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;
import java.util.Map;
import java.util.HashMap;


/**
 * Created by fujia on 2016/5/30.
 */
public class BlockActionCatalog extends ActionSupport {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private HashMap<String,Object> data;
	
	private BlockServiceCatalogImpl blockServiceCatalog;

	public void setBlockServiceCatalog(BlockServiceCatalogImpl blockServiceCatalog) {
		this.blockServiceCatalog = blockServiceCatalog;
	}

	@Override
    public String execute() throws Exception {
        List<String> title = this.blockServiceCatalog.getAllTitle();
        List<String> text = this.blockServiceCatalog.getAllText();

        Sessions.setSession("title", title);
        Sessions.setSession("text", text);

        return SUCCESS;
    }

    public String jsonForBlock() {
        List<String> title = this.blockServiceCatalog.getAllTitle();
        List<String> text = this.blockServiceCatalog.getAllText();

        // dataMap中的数据将会被Struts2转换成JSON字符串，所以这里要先清空其中的数据
        this.data = new HashMap<>();

        this.data.put("title", title);
        this.data.put("text", text);
        // 放入一个是否操作成功的标识
        this.data.put("success", true);

        // 返回结果
        return SUCCESS;
    }

    public Map<String, Object> getData() {
        return data;
    }



}
